package com.wao.menu.service.mapper;

import com.wao.menu.domain.Item;
import com.wao.menu.service.dto.ItemTreeDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * Mapper for the entity Item and its Tree DTO ItemTreeDTO.
 */
@Mapper(componentModel = "spring", uses = {})
public interface ItemTreeMapper extends EntityMapper<ItemTreeDTO, Item> {

    @Mapping(source = "parent.id", target = "parentId")
    ItemTreeDTO toDto(Item item);

    @Mapping(source = "parentId", target = "parent")
    Item toEntity(ItemTreeDTO itemTreeDTO);

    default Item fromId(Long id) {
        if (id == null) {
            return null;
        }
        Item item = new Item();
        item.setId(id);
        return item;
    }
}
